﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Espam.Idiomas.Decimo.Tesis.Negocio;
using System.Reflection;
using System.Drawing;

namespace Espam.Idiomas.Decimo.Tesis.Web
{
    public partial class UI_Block : System.Web.UI.Page
    {
        string validaSession = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
                Response.Cache.SetAllowResponseInBrowserHistory(false);
                Response.Cache.SetNoStore();

                if (Session["userEspamIdiomasVarSession001"] == null || Session["rolEspamIdiomasVarSession003"] == null)
                {
                    validaSession = "NoHaIniciadoSession";
                    Response.Redirect("UI_Login.aspx?validaSession=" + validaSession);
                }
                else if (Session["userEspamIdiomasVarSession001"] != null && Session["rolEspamIdiomasVarSession003"].ToString() == "Docente")
                {
                    Response.Redirect("UI_DashboardTeacher.aspx");
                }
                else if (Session["userEspamIdiomasVarSession001"] != null && Session["rolEspamIdiomasVarSession003"].ToString() == "Administradores")
                {

                    MaintainScrollPositionOnPostBack = true;
                    DataLoad();

                }
                else if (Session["userEspamIdiomasVarSession001"] != null && Session["rolEspamIdiomasVarSession003"].ToString() == "Alumno")
                {
                    Response.Redirect("UI_DashboardStudents.aspx");
                }
            }
            else
            {
                MaintainScrollPositionOnPostBack = true;
                
            }
        }

        

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string message = string.Empty;
            ListadoSemestres oSe = new ListadoSemestres();
            oSe.idSemestre = int.Parse(HfDeleteID.Value);
           // oSe.block = 1;
            message = oSe.BlockSemestre();
            if (message=="correcto")
            {
                lblvalida.Text = "Perfecto";
                lblvalida.ForeColor = Color.Green;
            }
           
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(@"<script type='text/javascript'>");
            sb.Append("alert('Realizado Correctamente');");
            sb.Append("$('#flexModal').modal('hide');");
            sb.Append(@"</script>");
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "delHideModalScript", sb.ToString(), false);
            Response.Redirect("UI_Block.aspx");
        }
        private void DataLoad()
        {
            ListadoSemestres oSemestre = new ListadoSemestres();

            List<Semestre> lista = new List<Semestre>();
            lista = oSemestre.GetSemestres();
            gvReprobados.DataSource = lista;
            gvReprobados.DataBind();

        }

        protected void gvReprobados_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            string id = gvReprobados.DataKeys[index].Value.ToString();
            HfDeleteID.Value = id;
            if (gvReprobados.Rows[index].Cells[1].Text=="DESBLOQUEADO")
            {
                lblMensajeDecision.Text = "DESEA BLOQUEAR EL ACCESSO A ESTE SEMESTRE?";
            }
            else
            {
                lblMensajeDecision.Text = "DESEA DESBLOQUEAR EL ACCESSO A ESTE SEMESTRE?";
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
        }

        protected void btnAbrePopup_Click(object sender, EventArgs e)
        {

        }
    }
}